package com.tiancheng.trade.order.util.cmq.queue.producer;

import com.tiancheng.trade.commom.core.utils.JsonUtil;
import com.tiancheng.trade.order.bo.cmq.VipMsgBO;
import com.tiancheng.trade.commom.core.data.MessageBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.UUID;

/**
 * 会员系统
 * @Author: likailun
 * @Description: 消息推送
 * @Date: create in 2022/7/29 11:22 AM
 */
@Slf4j
@Component
public class VipMessageProducer {
    public static final int ACTION_CANCEL=182;
    public static final int ACTION_REFUND=181;
    public static final int ACTION_VERIFICATION=183;
    public static final int ACTION_PAY=187;


    /**
     * 退款
     *
     * @param refundMsgBO
     */
    public boolean sendVipMsg(VipMsgBO refundMsgBO) {
        try {
            /*MessageBody msgBody = this.getMsgData("point-produce-behavior", refundMsgBO);
            String msgBodyStr = JsonUtil.toJsonString((msgBody);

            log.info("推送会员系统消息message:{}", msgBodyStr);

            TopicProducer producer = cmqProducer.getTopic(cmqTopic);
            String s=producer.publishMessage(msgBodyStr);
            log.info("推送会员系统消息messageId:{}", s);*/
            return true;
        } catch (Exception e) {
            log.error("cmq推送会员系统消息失败:{}, {}", JsonUtil.toJsonString(refundMsgBO), e.getMessage(), e);
            return false;
        }
    }

    /**
     * 组织生成消息内容
     * @param data
     * @return
     */
    private MessageBody getMsgData(String messageType, Object data) {
        MessageBody messageBody = new MessageBody();
        messageBody.setMessageType(messageType);
        messageBody.setData(data);
        messageBody.setNonce(UUID.randomUUID().toString().replace("-", ""));
        messageBody.setTimestamp(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));

        /*Optional<String> sign = MessageSign.get(JacksonUtils.conversion(JsonUtil.toJsonString((messageBody), TreeMap.class), signKey);
        messageBody.setSign(sign.get());*/
        return messageBody;
    }
}
